﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SharedGenomics.Core;

namespace SharedGenomics.Workbench.Models
{
    public class MissingMarkersModel : IMissingMarkersModel
    {
        public MissingMarkersModel()
        {
            this.MissingMarkers = new List<string>();
        }

        public bool RemoveMarker(string markerName)
        {
            bool markerRemoved = this.MissingMarkers.Remove(markerName);

            //if an item was removed, notify the list has changed
            if (markerRemoved)
                this.ListChanged.Raise(this);

            return markerRemoved;
        }

        public void LoadMarkers(IEnumerable<string> missingMarkers)
        {
            //clear the list of markers and re-fill with the input markers
            this.MissingMarkers.Clear();

            //create hashset of the input enumeration to filter out duplicate marker names
            HashSet<string> uniqueMarkerNames = new HashSet<string>(missingMarkers ?? Enumerable.Empty<string>());

            this.MissingMarkers.AddRange(uniqueMarkerNames);
            this.ListChanged.Raise(this);
        }

        public IEnumerable<string> Items
        {
            get { return this.MissingMarkers; }
        }

        public event EventHandler ListChanged;

        private List<string> MissingMarkers { get; set; }
    }
}
